from django.db import models
from sync.models import SFObject,SFField
from django.db.models import Q
from django.db import connection, transaction
from wizard.models.view import View
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response

class FormView(View):
    url_after_save=models.CharField(max_length=255,default="")
    view_after_save=models.ForeignKey(View,related_name='view_after_save',null=True)
    
    class Meta:
        db_table = 'wizard_form_view'
        app_label = 'wizard'
    """
    View using functions
    """
    def redirect(self,request):
        if self.url_after_save:
            return HttpResponseRedirect(self.url_after_save)
        if self.view_after_save:
            return HttpResponseRedirect("/wizard/views/%s/"%self.url_after_save.name)
    def save_form(self,request):
        return True
    def resp(self,request,dev=False):
        if request.method=="POST":
            if self.save_form(request):
                return self.redirect(request)
        if self.custom_html:
            form=self.load(request)
            return render_to_response(self.custom_html , 
                              {'form':form},
                              context_instance = RequestContext(request))
        if self.custom_html:
            rendered=self.render(request)
            #TODO: add search form
            #TODO: add custom blocks
            return render_to_response('wizard/views/form.html', 
                              {'rendered':rendered},
                              context_instance = RequestContext(request))
    def load(self,request):
        pass
    def get_where(self):
        pass
    def get_sort(self):
        pass
    def render(self):
        pass
    def save_form(self,request):
        pass
